<?php
function addRequest($from, $to)
{
    if(existsRequest($from, $to)) return 0;
    $sql = "INSERT INTO `friendrequest` 
            VALUE('{$from}', '{$to}')";
    if(mysqli_query(getDB(), $sql)) return 1;
    return 0;
}

function existsRequest($from, $to)
{
    $sql = "SELECT * 
            FROM `friendrequest` 
            WHERE 
                req_from = '{$from}' AND req_to = '{$to}'";
    if(($result = mysqli_query(getDB(), $sql)) and mysqli_num_rows($result) > 0)
    {
        return TRUE;
    }
    return FALSE;
}

function getAllRequest($user_id)
{
    return getList(
            "friendrequest LEFT JOIN profiles ON friendrequest.req_from = profiles.UserId", 
            array("friendrequest.*","`profiles`.`fullname`"), 
            "req_to = '{$user_id}'"
            );
}
?>
